// https://blog.csdn.net/rxbook/article/details/130646031

package main

import (
	"fmt"
	"time"
)

type rxbook struct {
	name string
}

//	func (rx *rxbook) print() {
//		fmt.Print(rx.name, " ") //输出结果: mongodb mongodb php mongodb golang java (顺序可能不一致,是由于 Goroutine 调度顺序不同,下同)
//	}
func (rx rxbook) print() {
	fmt.Print(rx.name, " ") //输出结果:mongodb mysql redis php java golang
}

func main() {
	data1 := []*rxbook{{"php"}, {"golang"}, {"java"}}
	for _, v := range data1 {
		go v.print() //等价于下面一行代码:
		//go (*rxbook).print(v)
	}
	data2 := []rxbook{{"mysql"}, {"redis"}, {"mongodb"}}
	for _, v := range data2 {
		go v.print() //等价于下面一行代码:
		//go (*rxbook).print(&v)
	}
	time.Sleep(time.Second * 1)
	println()

}
